package com.example.caoben_back.mapper;

import com.example.caoben_back.entity.po.ProvinceWeather;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 各省份天气信息表 Mapper 接口
 * </p>
 *
 * @author ylsink
 * @since 2025-11-11
 */
public interface ProvinceWeatherMapper extends BaseMapper<ProvinceWeather> {
    // 批量更新天气信息（根据省份名称）
    @Update("<script>" +
            "UPDATE province_weather " +
            "<set>" +
            "weather = CASE province " +
            "<foreach collection='list' item='item' separator=''>" +
            "WHEN #{item.province} THEN #{item.weather} " +
            "</foreach>" +
            "END, " +
            "temperature_float = CASE province " +
            "<foreach collection='list' item='item' separator=''>" +
            "WHEN #{item.province} THEN #{item.temperatureFloat} " +
            "</foreach>" +
            "END, " +
            "humidity_float = CASE province " +
            "<foreach collection='list' item='item' separator=''>" +
            "WHEN #{item.province} THEN #{item.humidityFloat} " +
            "</foreach>" +
            "END, " +
            "update_time = NOW() " +
            "</set>" +
            "WHERE province IN " +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "#{item.province}" +
            "</foreach>" +
            "</script>")
    int batchUpdateByProvince(List<ProvinceWeather> list);
}
